package com.example.app_mqttclient.activity;

import com.example.app_mqttclient.R;
import com.example.app_mqttclient.obj.MqttData;
import com.example.app_mqttclient.obj.MyMqttClient;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class LightDevActivity extends Activity {

    private static final String TAG = "LightDevActivity";

    private String pubTopic = null;
    private String subTopic = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_light_dev);

        Intent intent = this.getIntent(); // 获取当前Intent
        Bundle bundle = intent.getExtras(); // 从Intent中获取携带数据的Bundle
        MqttData mqttData = (MqttData) bundle.getSerializable("topic"); // 从Bundle中获取数据 用key对应查找
        this.pubTopic = mqttData.getPublishTopic();
        this.subTopic = mqttData.getSubscribeTopic();
    }
    /**
     * @brief   照明设备操作页面的按键点击处理
     * @param   view: view对象
     * @retval  None
     */
    public void lightDevActivityOnClick(View view) {
        switch (view.getId())
        {
            case R.id.device_light_btn_back:
                Log.i(TAG, "headbar back btn OnClick");
                this.finish(); // 结束当前页面
                break;
            case R.id.device_light_open:
                Log.i(TAG, "light open btn OnClick");
                MyMqttClient.mqttPublish(this.subTopic, "RELAY1:on");
                break;
            case R.id.device_light_close:
                Log.i(TAG, "light close btn OnClick");
                MyMqttClient.mqttPublish(this.subTopic, "RELAY1:off");
                break;
        }
    }
}